<template>
  <div class='search'>
    <f-form ref='form' :action='api.bod' :form-key='this.formItem.orderDetailsId'>
      <f-form-item label='发票号码' name='invoiceNo' :value='formItem.invoiceNo' />
      <f-form-item label='发票金额' type='number' :precision='4' data-type='number' name='invoiceAmount' :value='formItem.invoiceAmount' />
      <f-form-item label='发票日期' type='date' name='invoiceDate' :value='formItem.invoiceDate' />
      <a-divider orientation='center'>发货信息</a-divider>
      <f-form-item label='发货单号' name='sendNo' :value='formItem.sendNo' />
      <f-form-item label='发票收件地址' ref='customFpId' type='select' name='customFpId' :value='formItem.customFpId' :data='api.customAddress.list' valueKey='customAddressId' label-key='userName,address,telephone' v-show='invoiceSendType==2' :dropdown-render='true' @addItem='addItem2' />
      <f-form-item label='随发票资料' name='invoiceAttachment' :value='formItem.invoiceAttachment' />
      <f-form-item label='随货资料' name='sendAttachment' :value='formItem.sendAttachment' />
    </f-form>
    <custom-address-modal ref='addressModal' :addressType='addressType' :custom-id='this.params1.customId' @handleSuccess='handleSuccess'></custom-address-modal>
  </div>
</template>
<script>
import api from "../js/api"
import CustomAddressModal from "../../custom/custom_address_modal"

export default {
  name: "orderCalculateTab3",
  props: {},
  data() {
    return {
      refs: this.$refs,
      loadDept: false,
      supplieBtn: true,
      amountTitle: "回款日期",
      invoiceSendType: 1,
      addressType: 1,
      params1: {
        customId: "",
        addressType: 1
      },
      orderId: "",

      api: Object.assign(api, this.api),
      isAdd: true,//是否是添加模式
      loaded: false,//是否加载完成
      formItem: this.getFormItem()
    }
  },
  methods: {
    getFormItem() {
      return {
        orderId: "",
        orderNo: "",
        delivery: "",
        saleManName: "",
        sendNo: "",
        customName: "",
        invoiceSendType: 0,
        reputation: "",
        reputationAmount: "",
        bankId: "",
        customBondType: 0,
        supplierBondType: 0,
        customId: "",
        billsType: "",
        remark: ""
      }
    },
    //表单赋值
    setData(data) {
      this.$refs.form.resetFields()
      this.formItem = this.getFormItem()
      if (data && data.orderDetailsId) {
        this.invoiceSendType = data.invoiceSendType
        if (this.invoiceSendType == 2) {
          this.$refs["customFpId"].initData({
            customId: data.customId,
            addressType: 2
          })
        }
        this.params1.customId = data.customId
        this.http.get(this, {
          url: this.api.bod.get,
          params: {
            orderDetailsId: data.orderDetailsId,
            handlerName: "calCulateTab1GetHandler"
          },
          success: function(me, data) {
            me.formItem = data
          }
        })
      }
    },
    addItem(data) {
      this.customShData = data
      this.addressType = 1
      this.$refs["addressModal"].showModal()
    },
    addItem2(data) {
      this.customFpData = data
      this.addressType = 2
      this.$refs["addressModal"].showModal()
    },
    //地址自定义添加回调
    handleSuccess(data) {
      if (this.addressType == 1) {
        this.customShData.push(data)
      } else {
        this.customFpData.push(data)
      }
    },
    //提交表单
    handleSubmit(callback) {
      this.$refs.form.submit({
        orderId: this.formItem.orderId,
        drugsId: this.formItem.drugsId,
        drugsLotId: this.formItem.drugsLotId,
        optType: 4,
        customId: this.formItem.customId,
        saleType: this.formItem.saleType
      }, callback)
    }
  },
  mounted() {

  },
  created() {
  },
  components: { CustomAddressModal }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
